/**
 * 基础菜单 店铺信息
 */
<template>
  <div>
    <!-- 面包屑导航 -->
    <el-breadcrumb v-if="hasSeller" separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>店铺管理</el-breadcrumb-item>
    </el-breadcrumb>
     <!-- 搜索筛选 -->
    <el-form :inline="true" v-if="hasSeller" :model="formInline" class="user-search" >
      <el-form-item v-if="hasSeller">
        <el-button size="small" :disabled="sellStatus != 5" type="primary" icon="el-icon-edit"  @click="handleEditYY(0)">{{yyText}}</el-button>
      </el-form-item>
       <el-form-item v-if="hasSeller">
        <el-button size="small" type="primary" icon="el-icon-edit"  @click="handleEditYY(1)">{{dpText}}</el-button>
      </el-form-item>
      <el-form-item>
        <el-button size="small" :disabled="sellStatus == 5 || sellStatus == 0" @click="handleEdit('0',row)">编辑</el-button>
      </el-form-item>
      <el-form-item>
          <el-button size="small" type="danger" @click="deleteUser('',row)">删除</el-button>
      </el-form-item>
       <el-form-item>
          <el-button size="small" type="danger" :disabled="sellStatus != 1"  @click="closeUser('',row)">关店</el-button>
      </el-form-item>
       <el-form-item>
          <el-button size="small" type="success" :disabled="sellStatus != 3" @click="openUser('',row)">开店</el-button>
      </el-form-item>
       <el-form-item>
           <el-button size="small"  :disabled="sellStatus != 5" @click="handleEdit('1',row)">重新申请</el-button>
      </el-form-item>
      <el-form-item label="新订单提醒">
        <el-switch :disabled="sellStatus != 1" v-model="voiceSwitch"
                active-value="1"
            inactive-value="0"
            @change=chang($event)
            >
        </el-switch>
      </el-form-item>
    </el-form>
    <div v-if="!isEnd">
      <div>
         
      </div>
      <el-steps :active="step" finish-status="success" process-status="process" simple>
        <el-step title="基本信息" icon="el-icon-edit"></el-step>
        <el-step title="营业执照" icon="el-icon-picture"></el-step>
        <el-step title="等待审核" icon="el-icon-upload"></el-step>
      </el-steps>
      <div v-if="step == 0">
        <div class="demo-type">
          <el-avatar :size="100"   icon='el-icon-s-custom'>
          </el-avatar>
        </div>
        <div style="width:100%;text-align:center;padding-top:20px">
            <el-button size="medium" type="primary" icon="el-icon-plus"  @click="handleEdit()">开通店铺</el-button>
        </div>
      </div>
      <div v-if="step == 1" class="demo-type">
         <el-upload class="upload-demo"
          action="上传的地址"
          list-type="picture-card"
          :limit='limitCount'
          :on-remove='handleYYRmove'
          :on-change="imageYYChange"
          :auto-upload="false"
          :file-list="fileList"
          ref="upload"
          accept=".jpg, .jpeg, .png"
          >
          <i class="el-icon-plus avatar-uploader-icon"></i>
        </el-upload>
        <div class="el-upload__tip">请上传营业执照，png、jpg及jpeg格式图片(大小2M以下,建议分辨率256*256)</div>
        <div slot="footer" class="dialog-footer">
          <el-button size="medium" type="primary" :loading="loading" class="title" @click="submitFormYY(0)">保存</el-button>
        </div>
      </div>
      <div v-if="step == 2">
        <div class="demo-type">
          <el-avatar :size="100"   icon='el-icon-success'>
          </el-avatar>
        </div>
        <div style="width:100%;text-align:center;padding-top:20px">
            <el-button size="medium" type="primary" icon="el-icon-plus"  @click="search()">进入我的店铺</el-button>
        </div>
      </div>
    </div>
    <!--列表-->
    <el-form :model="row" v-if="hasSeller"  ref="ruleForm" label-width="200px" class="demo-ruleForm">
       <el-form-item  prop="sellerNo" label="店铺编号：">
        <div class="showText">{{row.sellerNo}}</div>
      </el-form-item>
      <el-form-item label="头像：" prop="photo">
        <div style="width:500">
          <img :src="row.photo"  width="100" height="100"/>
        </div>
      </el-form-item>
       <el-form-item  prop="sellerName" label="店铺名称：">
        <div class="showText">{{row.sellerName}}</div>
      </el-form-item>
      <el-form-item  prop="serveType" label="服务类型：">
        <div class="showText"> {{row.serveType}}</div>
      </el-form-item>
       <el-form-item  prop="creditPoint" label="信用值：" >
         <div class="showText">{{row.creditPoint}}</div>
         
      </el-form-item>
      <el-form-item  prop="address" label="店铺地址：" >
        <div class="showText">{{row.address}}</div>
        
      </el-form-item>
       <el-form-item  prop="phoneNum" label="店铺联系方式：">
         <div class="showText"> {{row.phoneNum}}</div>
        
      </el-form-item>
      <el-form-item  prop="minServePrice" label="服务价：">
        <div class="showText">{{row.minServePrice}}</div>
        
      </el-form-item>
      <el-form-item  prop="visitPrice" label="上门费：" >
        <div class="showText">{{row.visitPrice}}</div>
        
      </el-form-item>
      <el-form-item  prop="remark" label="备注：" >
        <div class="showText">{{row.remark}}</div>
        
      </el-form-item>
      <el-form-item  prop="status" label="店铺状态：" >
        <div class="showText">{{row.status}}</div>
        
      </el-form-item>
       <el-form-item  prop="registDate" label="注册时间：" >
         <div class="showText">{{row.registDate}}</div>
         
      </el-form-item>
      
    </el-form>
    <!-- <el-table v-if="hasSeller" size="small" :data="listData" highlight-current-row v-loading="loading" border element-loading-text="拼命加载中" style="width: 100%;">
      <el-table-column align="center" type="selection" width="60">
      </el-table-column>
      <el-table-column sortable prop="photo" label="店铺头像"  width="130">
          <template slot-scope="scope">            
            <img :src="scope.row.photo"  width="100" height="100" />
          </template>
      </el-table-column>
      <el-table-column sortable prop="sellerName" label="店铺名称" width="200">
      </el-table-column>
      <el-table-column sortable prop="serveType" label="服务类型" width="120">
      </el-table-column>
       <el-table-column sortable prop="creditPoint" label="信用值" width="150">
      </el-table-column>
      <el-table-column sortable prop="address" label="店铺地址" width="300">
      </el-table-column>
       <el-table-column sortable prop="phoneNum" label="店铺联系方式" width="150">
      </el-table-column>
      <el-table-column sortable prop="minServePrice" label="服务价" width="100">
      </el-table-column>
      <el-table-column sortable prop="visitPrice" label="上门费" width="100">
      </el-table-column>
      <el-table-column sortable prop="remark" label="备注" width="300">
      </el-table-column>
      <el-table-column sortable prop="status" label="店铺状态" width="100">
      </el-table-column>
       <el-table-column sortable prop="registDate" label="注册时间" width="150">
      </el-table-column>
      
      <el-table-column align="center" label="操作" min-width="300">
        <template slot-scope="scope">
          <el-button size="mini" :disabled="sellStatus == 5 || sellStatus == 0" @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
          <el-button size="mini" type="danger" @click="deleteUser(scope.$index, scope.row)">删除</el-button>
          <el-button size="mini" type="danger" v-if="sellStatus == 1"  @click="closeUser(scope.$index, scope.row)">关店</el-button>
          <el-button size="mini" type="success" v-if="sellStatus == 3" @click="openUser(scope.$index, scope.row)">开店</el-button>
           <el-button size="mini"  v-if="sellStatus == 5" @click="handleEdit(scope.$index, scope.row)">重新申请</el-button>
        </template>
      </el-table-column>
    </el-table> -->
    <!-- 编辑界面 -->
    <el-dialog :title="title" :visible.sync="editFormVisible" width="50%" @click="closeDialog">
      <el-form label-width="100px" :model="editForm" :rules="rules" ref="editForm">
        <el-form-item label="店铺名称" prop="sellerName">
          <el-input size="small" :disabled="hasSeller && sellStatus != 5" v-model="editForm.sellerName" auto-complete="off"></el-input>
        </el-form-item>
         <el-form-item size="small" label="店铺类型" prop="string">
          <el-select clearable size='small' :disabled="hasSeller && sellStatus != 5" v-model="editForm.serveType" placeholder="请选择店铺类型" autocomplete="off"
                     style="width: 100%">
            <el-option v-for="item in dictServeType" :key="item.value" :label="item.value" :value="item.name">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="店铺地址" prop="address">
          <template>
            <div class="linkage">
              <div>
              <el-select v-model="selectProvince" filterable size="small" @change="selectProvinceFun($event)" placeholder="请选择省份">
                <!-- <el-option value="" label="请选择省份"></el-option> -->
                <el-option :value="item" :label="item.label" v-for="(item, index) in city" :key="index"></el-option>
              </el-select>
              </div>
              <div>
              <el-select v-model="selectCity" filterable size="small" @change="selectCityFun($event)" placeholder="请选择城市">
                <!-- <el-option value="" label="请选择城市"></el-option> -->
                <el-option :value="item" :label="item.label" v-for="(item, index) in cityList" :key="index"></el-option>
              </el-select>
              </div>
              <div>
              <el-select v-model="selectArea" filterable size="small" @change="selectAreaFun($event)" placeholder="请选择区县">
                <!-- <el-option value="" label="请选择区县"></el-option> -->
                <el-option :value="item" :label="item.label" v-for="(item, index) in areaList" :key="index"></el-option>
              </el-select>
              </div>
            </div>
             <el-input size="small" placeholder="请填写详细地址" v-model="editForm.address" auto-complete="off"></el-input>
            </template>
        </el-form-item>
        <el-form-item label="联系电话" prop="phoneNum">
          <el-input size="small" v-model="editForm.phoneNum" auto-complete="off"></el-input>
        </el-form-item>
        <el-form-item label="店铺描述" prop="remark">
          <el-input size="small" v-model="editForm.remark" auto-complete="off" placeholder="请填写店铺营业时间等相关描述"></el-input>
        </el-form-item>
         <el-form-item label="服务价" prop="minServePrice">
          <el-input size="small" v-model="editForm.minServePrice" auto-complete="off"></el-input>
        </el-form-item>
         <el-form-item label="上门费" prop="visitPrice">
          <el-input size="small" v-model="editForm.visitPrice" auto-complete="off"></el-input>
        </el-form-item>
        <el-form-item label="店铺头像" prop="photo">
           <el-upload class="upload-demo"
            action="上传的地址"
            list-type="picture-card"
            :limit='1'
            :on-remove='handleRmove'
            :on-change="imageChange"
            :auto-upload="false"
            :file-list="fileList"
            ref="upload"
            accept=".jpg, .jpeg, .png"
            >
            <i class="el-icon-plus avatar-uploader-icon"></i>
          </el-upload>
          <div class="el-upload__tip">请上传png、jpg及jpeg格式图片(大小2M以下,建议分辨率256*256)</div>
        </el-form-item>
       
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button size="small" @click="closeDialog">取消</el-button>
        <el-button size="small" type="primary" :loading="loading" class="title" @click="submitForm('editForm')">保存</el-button>
      </div>
    </el-dialog>

    <!-- 营业执照照片上传界面 -->
    <el-dialog :title="title" :visible.sync="editYYPhotoVisible" width="50%" @click="closeYYDialog">
        <el-upload class="upload-demo"
        action="上传的地址"
        list-type="picture-card"
        :limit='limitCount'
        :on-remove='handleYYRmove'
        :on-change="imageYYChange"
        :auto-upload="false"
        :file-list="fileList"
        ref="upload"
        accept=".jpg, .jpeg, .png"
        >
        <i class="el-icon-plus avatar-uploader-icon"></i>
      </el-upload>
      <div class="el-upload__tip">请上传{{showText}}，png、jpg及jpeg格式图片(大小2M以下,建议分辨率256*256)</div>
      <div slot="footer" class="dialog-footer">
        <el-button size="small" @click="closeYYDialog">取消</el-button>
        <el-button size="small" type="primary" :loading="loading" class="title" @click="submitFormYY()">保存</el-button>
      </div>
    </el-dialog>
     <!-- 展示优惠券 -->
    <el-dialog :title="title" :visible.sync="editFormVisibleYHQ" width="70%"  @click="closeDialogYHQ">
       <el-table size="small" :data="listDatayhq" highlight-current-row v-loading="loading" border element-loading-text="拼命加载中" style="width: 100%;">
          <el-table-column sortable prop="satisfyAmount" label="满足金额" width="150">
          </el-table-column>
          <el-table-column sortable prop="discountAmount" label="折扣金额" width="150">
          </el-table-column>
          <el-table-column sortable prop="descri" label="描述" width="300">
          </el-table-column>
          <el-table-column sortable prop="type" label="优惠券类型" width="120">
          </el-table-column>
           <el-table-column align="center" label="操作" min-width="150">
            <template slot-scope="scope">
              <el-button size="mini" type="success" v-if="scope.row.hasFlag == null"  @click="addDiscount(scope.$index, scope.row)">添加</el-button>
              <el-button size="mini" type="danger" v-if="scope.row.hasFlag != null" @click="removeDiscount(scope.$index, scope.row)">移除</el-button>
            </template>
          </el-table-column>
        </el-table>
    </el-dialog>
  </div>
</template>

<script>
import { sellerList, sellerUpdate, sellerAdd,sellerDel ,dictList,yyPhotoList,yyPhotoSave,sellerClose,sellerOpen
,disCountList,disCountAdd,disCountRemove } from '../../api/sellerMG'
import Pagination from '../../components/Pagination'
import { objectToFormData } from 'object-to-formdata';
import city from '@/assets/json/city.json'
import { stringToByte,dataURLtoBlob,base64ToArrayBuffer} from '../../utils/util'
export default {
  data() {
     const validateAddr = (rule,value,callback) =>{
        if(value == ''){
          callback(new Error('请输入店铺详细地址'));
        }else if(Object.keys(this.selectProvince).length <= 0){
          callback(new Error('请选择省级'));
        }else if(Object.keys(this.selectCity).length <= 0){
          callback(new Error('请选择市级'));
        }else if(Object.keys(this.selectArea).length <= 0){
          callback(new Error('请选择县/区'));
        }else{
          callback();
        }
      }
    return {
      voiceSwitch:0,
      // 整个省市县数据
      city: city,
      // 被选中的市数据
      cityList: [],
      // 被选中的县数据
      areaList: [],
      selectProvince: {},
      selectCity: {},
      selectArea: {},
      row:{},
      isEnd:true,
      step:0,
      yyText:'新增营业执照',
      dpText:'新增店铺照片',
      saveText:'',
      sellStatus:0,
      ptype:0,
      limitCount:2,
      showText:'',
      sellerNo:'',
      editYYPhotoVisible:false,
      editFormVisibleYHQ: false,
      serveSelect:'0',
      dictServeType:[],
      nshow: true, //switch开启
      fshow: false, //switch关闭
      loading: false, //是显示加载
      editFormVisible: false, //控制编辑页面显示与隐藏
      title: '添加',
      hasSeller:false,
      fileList:[],
      images:[],
      haspic:false,
      dictNameParam:{
        typeNo:3
      },
      editForm: {
        sellerNo:'',
        sellerName:"",
        address:"",
        phoneNum:"",
        remark:"",
        serveType:"0",
        minServePrice:'',
        visitPrice:'',
        province:'',
        city:'',
        area:'',
        tokenId: localStorage.getItem('tokenId')
      },
      // rules表单验证
      rules: {
        sellerName: [
          { required: true, message: '请输入店铺名', trigger: 'blur' }
        ],
        address: [{ required: true, validator:validateAddr, trigger: 'blur' }],
        phoneNum: [{ required: true, message: '请输入店铺联系方式', trigger: 'blur' }],
        remark: [{ required: true, message: '请输入店铺描述信息', trigger: 'blur' }],
        serveType: [{ required: true, message: '请输入店铺服务类型', trigger: 'blur' }],
         minServePrice: [{ required: true, message: '请输入服务价', trigger: 'blur' }],
        visitPrice: [{ required: true, message: '请输入上门费', trigger: 'blur' }]

      },
      formInline: {
        pageIndex: 1,
        pageSize: 10,
        tokenId: localStorage.getItem('tokenId')
      },
      // 删除部门
      seletedata: {
        ids: '',
        tokenId: localStorage.getItem('tokenId')
      },
      userparm: [], //搜索权限
      listData: [], //用户数据
      listDatayhq:[],//优惠券数据
      // 分页参数
      pageparm: {
        currentPage: 1,
        pageSize: 10,
        total: 10
      }
    }
  },
  // 注册组件
  components: {
    Pagination
  },
  /**
   * 数据发生改变
   */

  /**
   * 创建完毕
   */
  created() {
    this.step = localStorage.getItem('step')-0;
    this.getdata(this.formInline)
    
  },
  mounted(){
     dictList(this.dictNameParam)
            .then(res => {
              if (res.code == "1") {
                this.dictServeType = res.data
              } else {
                this.$message({
                  type: 'info',
                  message: res.msg
                })
              }
            })
  },

  /**
   * 里面的方法只有被调用才会执行
   */

  methods: {
    chang(event){
      sessionStorage.setItem('openVoice',event);
    },
      // 省份 市 县联动
      selectProvinceFun (event) {
        if (event) {
          this.cityList = event.children
          this.editForm.province = event.value;
          this.selectArea={}
          this.selectCity={}
        } else {
          this.cityList = []
        }
        this.areaList = []
        this.$emit('getLawyerListInfo', [event.label, 'province'])
      },
      selectCityFun (event) {
        if (event) {
          this.editForm.city = event.value;
          this.areaList = event.children
        } else {
          this.areaList = []
        }
        this.$emit('getLawyerListInfo', [event.label, 'city'])
      },
      selectAreaFun (event) {
        this.editForm.area = event.value;
        this.$emit('getLawyerListInfo', [event.label, 'area'])
      },
     imageYYChange(file, fileList, name) {//on-change触发
        this.fileList = fileList
      },
      handleYYRmove(file,fileList,name){
        this.fileList = fileList
      },
      imageChange(file, fileList, name) {//on-change触发
        this.fileList = fileList
        this.images.push(fileList[0].raw)
      },
      handleRmove(file,fileList,name){
        this.fileList = []
        this.images = [];
      },
    // 获取公司列表
    getdata(parameter) {
      this.loading = true

      /***
       * 调用接口，注释上面模拟数据 取消下面注释
       */
      sellerList(parameter)
        .then(res => {
          this.loading = false
          if (res.code == "0") {
            this.$message({
              type: 'info',
              message: res.msg
            })
          } else {

            for(let i = 0;i<res.data.datas.length;i++){
              this.sellStatus = res.data.datas[i].status_ori
              this.sellerNo = res.data.datas[i].sellerNo
              localStorage.setItem('sellerNo',res.data.datas[i].sellerNo)
              res.data.datas[i].photo = 'data:image/png;base64,'+res.data.datas[i].photo;
              this.row = res.data.datas[i];
            }
           
            //如果已经有店铺，隐藏添加按钮
            if(res.data.datas.length > 0){
              this.handleEditYY(0);
              this.handleEditYY(1);
              this.editYYPhotoVisible = false;
              this.saveText = '保存';
            }else{
              this.saveText = '开通店铺';
              localStorage.removeItem("isEnd");
              localStorage.setItem("step",0);
              this.step = 0;
              this.isEnd = false;
              this.hasSeller = false
            }
            this.listData = res.data.datas
            // 分页赋值
            this.pageparm.currentPage = this.formInline.pageIndex
            this.pageparm.pageSize = this.formInline.pageSize
            this.pageparm.total = res.data.total
          }
        })
        .catch(err => {
          this.loading = false
          this.$message.error('菜单加载失败，请稍后再试！')
        })
    },
    // 分页插件事件
    callFather(parm) {
      this.formInline.pageIndex = parm.currentPage
      this.formInline.pageSize = parm.pageSize
      this.getdata(this.formInline)
    },
    // 搜索事件
    search() {
      this.isEnd = true;
      localStorage.setItem("isEnd",1);
      this.getdata(this.formInline)
    },
    //显示编辑界面
    handleEdit: function(index, row) {
      this.isRetry = index;
      this.fileList = [];
      this.images = [];
      if (row != undefined && row != 'undefined') {
        this.title = '修改'
        this.editForm.sellerNo = row.sellerNo
        this.editForm.sellerName = row.sellerName
        this.editForm.address = row.address
        this.editForm.phoneNum = row.phoneNum
        this.editForm.remark = row.remark
        this.editForm.serveType = row.serveType_ori
        this.editForm.minServePrice = row.minServePrice
        this.editForm.visitPrice = row.visitPrice
        for(let i = 0;i<this.city.length;i++){
          if(this.city[i].value == row.province){
            this.selectProvince = this.city[i];
            this.cityList = this.selectProvince.children
            break;
          }
        }
        for(let i = 0;i<this.cityList.length;i++){
          if(this.cityList[i].value == row.city){
            this.selectCity = this.cityList[i];
            this.areaList = this.selectCity.children;
            break;
          }
        }
         for(let i = 0;i<this.areaList.length;i++){
          if(this.areaList[i].value == row.area){
            this.selectArea = this.areaList[i];
            break;
          }
        }
        console.log(this.selectCity);
        console.log(this.selectArea)
        let obj = new Object();
        obj.url = row.photo;
        let bytes = [];
        bytes.push(base64ToArrayBuffer(row.photo));
        let file = new File(bytes,"photo.png",null)
        this.images.push(file)
        this.fileList.push(obj)
      } else {
        this.title = '添加'
        this.editForm.sellerNo = ''
        this.editForm.sellerName = ''
        this.editForm.address = ''
        this.editForm.phoneNum = ''
        this.editForm.remark = ''
        this.editForm.serveType = ''
        this.editForm.minServePrice = ''
        this.editForm.visitPrice = ''
         this.editForm.province = ''
        this.editForm.city = ''
        this.editForm.area = ''
      }
      this.editFormVisible = true
    },
    yhqList(param){
       disCountList(param) .then(res => {
          this.loading = false
          if (res.code == "0") {
            this.$message({
              type: 'info',
              message: res.msg
            })
          } else {
            this.listDatayhq = res.data.datas
          }
        })
        .catch(err => {
          this.loading = false
          this.$message.error('优惠券加载失败，请稍后再试！')
        })
    },
    YHQEdit(){
      this.editFormVisibleYHQ = true
      let param = {
        pageIndex:1,
        pageSize:10000,
        sellerNo:localStorage.getItem("sellerNo")
      }
      this.yhqList(param);
    },
    addDiscount(index,row){
      let param = {
        sellerNo:localStorage.getItem("sellerNo"),
        discountNo:row.no
      }
      disCountAdd(param).then(res => {
              this.loading = false
              if (res.code == "1") {
                this.yhqList(param);
                this.$message({
                  type: 'success',
                  message: '添加成功！'
                })
              } else {
                this.$message({
                  type: 'info',
                  message: res.msg
                })
              }
            })
            .catch(err => {
              this.editFormVisible = false
              this.loading = false
              this.$message.error('优惠券添加失败，请稍后再试！')
            })
    },
    removeDiscount(index,row){
      let param = {
        no:row.hasFlag
      }
      disCountRemove(param).then(res => {
              this.loading = false
              if (res.code == "1") {
                this.yhqList(param);
                this.$message({
                  type: 'success',
                  message: '移除成功！'
                })
              } else {
                this.$message({
                  type: 'info',
                  message: res.msg
                })
              }
            })
            .catch(err => {
              this.editFormVisible = false
              this.loading = false
              this.$message.error('优惠券移除失败，请稍后再试！')
            })
    },
    handleEditYY(photoType){
      this.ptype = photoType
      this.fileList =[]
      this.editYYPhotoVisible = true
      if(photoType == 0){
        this.showText = '营业执照正反面'
      }else if(photoType == 1){
        this.showText = '店内照片'
        this.limitCount = 10
      }
      var param = {
        sellerNo:this.sellerNo,
        photoType:photoType,
        pageIndex:0,
        pageSize:10
      }
      yyPhotoList(param).then(res => {
          this.loading = false
          if (res.code == "0") {
            this.$message({
              type: 'info',
              message: res.msg
            })
          } else {
             let datas = res.data.datas;
             if(photoType == 0){
              //营业执照未上传，注册流程到第二步
              if(datas.length <= 0){
                localStorage.removeItem("isEnd");
                localStorage.setItem("step",1);
                this.step = 1;
                this.isEnd = false;
                this.hasSeller = false;
              }
                if(this.isEnd){
                  this.hasSeller = true;
                  localStorage.setItem("isEnd",1);
                  this.isEnd = true;
                }
             }
              if(datas.length > 0){
                if(photoType == 0){
                  this.yyText = '更新营业执照';
                }else if(photoType == 1){
                  this.dpText = '更新店铺照片';
                }
              }else{
                if(photoType == 0){
                  this.yyText = '新增营业执照';
                }else if(photoType == 1){
                  this.dpText = '新增店铺照片';
                }
              }
            for(let i = 0;i<res.data.datas.length;i++){
              let bytes = [];
              let obj = new Object();
              let photo = 'data:image/png;base64,'+res.data.datas[i].photo;
              obj.url = photo;
              bytes.push(base64ToArrayBuffer(photo));
              let file = new File(bytes,"photo.png",null)
              obj.raw = file
              this.fileList.push(obj)
            }
          }
        })
        .catch(err => {
          this.loading = false
          this.$message.error('照片加载失败，请稍后再试！')
        })
    },
    //保存照片
    submitFormYY(ptype){
      let param = {
        sellerNo:this.sellerNo,
        photoType:this.ptype
      }
      if(ptype != null && typeof(ptype) != undefined){
        param.photoType = ptype
      }
      if(this.fileList.length <= 0){
        this.$message.error('请选择照片！')
        return false;
      }
      if(ptype == 0 && this.fileList.length < 2){
        this.$message.error('请上传完整信息，包含营业执照正反面！')
        return false;
      }

      let formData = objectToFormData(param);
      for(let i = 0;i<this.fileList.length;i++){
        formData.append("photo"+i,this.fileList[i].raw);
      }
      yyPhotoSave(formData).then(res => {
        this.editYYPhotoVisible = false
        this.loading = false
        if (res.code == "1") {
          this.$message({
            type: 'success',
            message: '保存成功！'
          })
          this.handleEditYY(0);
          this.handleEditYY(1);
          this.editYYPhotoVisible = false;
          this.step = this.step+1
          localStorage.setItem('step',this.step);
        } else {
          this.$message({
            type: 'info',
            message: res.msg
          })
        }
      }).catch(err => {
          this.loading = false
          this.$message.error('照片保存失败，请稍后再试！')
        })
    },
    // 编辑、增加页面保存方法
    submitForm(editData) {
      if(this.images.length < 1){
        this.$message.error('请上传头像！')
        return false;
      }
      this.$refs[editData].validate(valid => {
        if (valid) {
          if(this.isRetry == '1'){
            this.editForm.status = 0
          }
          let formData = objectToFormData(this.editForm);
          formData.append("photo",this.images[0]);
          if(this.editForm.sellerNo == ''){
            sellerAdd(formData)
            .then(res => {
              this.editFormVisible = false
              this.loading = false
              if (res.code == "1") {
                this.isEnd = false;
                this.fileList = [];
                this.getdata(this.formInline)
                this.$message({
                  type: 'success',
                  message: '店铺信息保存成功！'
                })
                this.step = this.step+1;
                localStorage.setItem('step',this.step);
              } else {
                this.$message({
                  type: 'info',
                  message: res.msg
                })
              }
            })
            .catch(err => {
              this.editFormVisible = false
              this.loading = false
              this.$message.error('店铺信息保存失败，请稍后再试！')
            })
          }else{
            //修改店铺信息
            sellerUpdate(formData)
            .then(res => {
              console.log(res)
              this.editFormVisible = false
              this.loading = false
              if (res.code == "1") {
                this.getdata(this.formInline)
                this.$message({
                  type: 'success',
                  message: '店铺信息保存成功！'
                })
              } else {
                this.$message({
                  type: 'info',
                  message: res.msg
                })
              }
            })
            .catch(err => {
              this.editFormVisible = false
              this.loading = false
              this.$message.error('店铺信息保存失败，请稍后再试！')
            })
          }
          
        } else {
          return false
        }
      })
    },
    // 删除店铺
    deleteUser(index, row) {
      let param = {
        sellerNo : row.sellerNo
      }
      this.$confirm('确定要删除吗?', '信息', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          sellerDel(param)
            .then(res => {
              if (res.code == '1') {
                this.$message({
                  type: 'success',
                  message: '店铺已删除!'
                })
                this.getdata(this.formInline)
              } else {
                this.$message({
                  type: 'info',
                  message: res.msg
                })
              }
            })
            .catch(err => {
              this.loading = false
              this.$message.error('店铺删除失败，请稍后再试！')
            })
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          })
        })
    },
     // 关闭店铺
    closeUser(index, row) {
      let param = {
        sellerNo : row.sellerNo
      }
      this.$confirm('确定要关闭吗?', '信息', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          sellerClose(param)
            .then(res => {
              if (res.code == '1') {
                this.$message({
                  type: 'success',
                  message: '店铺已关闭!'
                })
                this.getdata(this.formInline)
              } else {
                this.$message({
                  type: 'info',
                  message: res.msg
                })
              }
            })
            .catch(err => {
              this.loading = false
              this.$message.error('店铺关闭失败，请稍后再试！')
            })
        })
    },
     //开店
    openUser(index, row) {
      let param = {
        sellerNo : row.sellerNo
      }
      this.$confirm('确定要开店吗?', '信息', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          sellerOpen(param)
            .then(res => {
              if (res.code == '1') {
                this.$message({
                  type: 'success',
                  message: '店铺已开启!'
                })
                this.getdata(this.formInline)
              } else {
                this.$message({
                  type: 'info',
                  message: res.msg
                })
              }
            })
            .catch(err => {
              this.loading = false
              this.$message.error('店铺开启失败，请稍后再试！')
            })
        })
    }
    ,
    // 关闭编辑、增加弹出框
    closeDialog() {
      this.editFormVisible = false
    }
    ,
    closeYYDialog(){
      this.editYYPhotoVisible = false
    },
    closeDialogYHQ(){
      this.editFormVisibleYHQ = false
    }
  }
}
</script>

<style scoped>
.user-search {
  margin-top: 20px;
}
.userRole {
  width: 100%;
}
.demo-type{
  width:100%;
  padding-top:40px;
  text-align:center
}
.showText{
  width: 100px
}
 .linkage {
  display: flex;
 }
  .linkage div:nth-child(-n+2) {
   margin-right: 6px;
  }
</style>

 
 